<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>Troy.Chen--管理系统--日志查询</title>
    <link rel="stylesheet" type="text/css" href="style/public.css"/>
    <link rel="stylesheet" type="text/css" href="style/query-log.css"/>
    <script charset="utf-8" type="text/javascript" src="/js/base64.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/ajax-1.1.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/public.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/query-map.js"></script>
    <script charset="utf-8" type="text/javascript" src="js/query.js"></script>
    <script type="application/javascript">
        openLoading();
        var q = null;
        window.onload = async function () {
            let urlQuery = new QueryMap();
            urlQuery.loadUrl();
            q = new QueryInfo();
            let urlPrefix = urlQuery.get("urlPrefix");
            if (!isNull(urlPrefix)) {
                q.urlPrefix = urlPrefix;
            }
            urlQuery.get("tableName");
            let tableName = urlQuery.get("tableName");
            q.tableName = tableName;
            let pageSize = urlQuery.get("pageSize");
            if (!isNull(pageSize)) {
                q.pageSize = pageSize;
            }
            let pageIndex = urlQuery.get("pageIndex");
            if (!isNull(pageIndex)) {
                q.pageIndex = pageIndex;
            }
            let queryWhere = urlQuery.get("queryWhere");
            if (!isNull(queryWhere)) {
                let decode = Base64.decode(queryWhere);
                q.queryWhere = JSON.parse(decode);
            }
            await q.init();
        }

        function changePage(change) {
            q.changePage(change);
        }

        function addQueryWhere() {
            let key = getSelectValue("sel_key");
            let sel_query_Key = getSelectValue("sel_query_Key");
            let value = $("txt_query").value;
            if (!isNull(value) || "$group" === sel_query_Key) {
                var oldValue = q.queryWhere[key];
                if (!(oldValue instanceof Object)) {
                    oldValue = {};
                }
                switch (sel_query_Key) {
                    case "=":
                    case "$gt":
                    case "$gte":
                    case "$lt":
                    case "$lte": {
                        oldValue[sel_query_Key] = value;
                    }
                        break;
                    case "$in":
                    case "$nin": {
                        oldValue = {};
                        oldValue[sel_query_Key] = value.split(",")
                    }
                        break;
                    case "$like": {
                        oldValue = {};
                        oldValue[sel_query_Key] = "%" + value + "%";
                    }
                        break;
                    case "$group": {
                        sel_query_Key = key;
                        key = "$group";
                        oldValue = q.queryWhere[key];
                        if (!(oldValue instanceof Object)) {
                            oldValue = {};
                        }
                        oldValue[sel_query_Key] = "$" + sel_query_Key;
                    }
                        break;
                    case "$or": {
                        sel_query_Key = key;
                        key = "$or";
                        oldValue = q.queryWhere[key];
                        if (!(oldValue instanceof Object)) {
                            oldValue = {};
                        }
                        oldValue[sel_query_Key] = value;
                    }
                        break;
                    default:
                        alert("无法识别！" + sel_query_Key);
                        break;
                }
                q.queryWhere[key] = oldValue;
                $('txt_query_where').value = JSON.stringify(q.queryWhere);
            } else {
                alert("请设置条件");
                $("txt_query").focus();
            }
            $("txt_query").value = "";
        }

        function queryWhere() {
            q.pageIndex = 1;
            q.init();
        }

        function reset() {
            $('txt_query_where').value = '';
            q.queryWhere = {};
            q.init();
        }

        function outExcel() {
            if (isNull(q) || isNull(q.dataCount) || q.dataCount < 1) {
                alert("查询结果没有数据！");
                return;
            }
            q.outExcel();
        }
    </script>
</head>
<body>
<div class="div_body_query">
    <ul>
        <li><span>查询&nbsp;</span></li>
        <li>
            <select id="sel_key">
                <option value="">编号</option>
            </select>
        </li>
        <li>
            <select id="sel_query_Key" style="width: 100px;">
                <option value="=" title="内容完全一直">精确查询</option>
                <option value="$like" title="内容包含">模糊查询</option>
                <option value="$gte" title="区间查询的时候最小值 包含">区间-Min</option>
                <option value="$lte" title="区间查询的时候最大值 包含">区间-Max</option>
                <option value="$in" title="用 , 分割多个数据，查询内容完全一直">包含</option>
                <option value="$nin" title="用 , 分割多个数据，查询内容完全一直">不包含</option>
                <option value="$group" title="分组查询，不需要参数">分组查询</option>
                <option value="$or" title="采用或的形式，多个条件查询，满足一个就行">多组查询</option>
            </select>
        </li>
        <li><input id="txt_query" type="text" value="" title="查询条件"/></li>
        <li><input type="button" value="添 加" onclick="addQueryWhere()"/></li>
    </ul>
    <div style="text-align: center;display: block;position: absolute;bottom: 5px;left: 5px">
        <ul>
            <li>条件:&nbsp;</li>
            <li><input id="txt_query_where" type="text" value="" style="width: 800px; "/></li>
        </ul>
        <ul style="margin-top: 5px">
            <li><input type="button" value="重 置" onclick="reset()"/></li>
            <li><input type="button" value="查 询" onclick="queryWhere()"/></li>
        </ul>
    </div>
</div>
<div class="div_body_content">
    <div class="div_page">
        &nbsp;
        <span>分页：</span>
        <span>
                <input type="button" value="<<" title="首页" onclick="changePage('<<')">
            <input type="button" value="<" title="上一页" onclick="changePage('<')">
            <input id="txt_page_index" size="6" style="text-align: center" type="text" value="0">
            <input type="button" value=">" title="下一页" onclick="changePage('>')">
            <input type="button" value=">>" title="尾页" onclick="changePage('>>')">
            </span>
        &nbsp;&nbsp;共&nbsp;<span id="span_data_count">0</span>&nbsp;条&nbsp;&nbsp; 每页&nbsp;
        <input id="txt_page_size" size="4" style="text-align: center" type="text"
               value="15"
               title="参数最小10条，最大1000条">
        &nbsp;条&nbsp;&nbsp;共&nbsp;<span id="span_page_max">0</span>&nbsp;页
        &nbsp;<a href="javascript:void(0);" onclick="outExcel();">导出Excel</a>
    </div>
    <div id="div_data" class="div_data">

    </div>
</div>
</body>
</html>